package com.tdam2011.grupo06.network;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import android.util.Log;
public class ResultParserSax {

	public ResultParserSax()
	{
	
	}
	
	public String[] requestUserRegistration(String user, String password)
	{
		SAXParserFactory factory = SAXParserFactory.newInstance();
		
		try
		{
			SAXParser parser = factory.newSAXParser();
			XmlResultHandler handler = new XmlResultHandler();
			parser.parse(Networking.requestUserRegistration(user,password), handler);
			return new String[]{String.valueOf(handler.getResult()),handler.getResultInfo()};
		}
		catch (Exception e)
		{
			throw new RuntimeException(e);
		}
	}
	
	public String[] requestSendMessage(String user, String password, String recipient, String message)
	{
		SAXParserFactory factory = SAXParserFactory.newInstance();
		
		try
		{
			SAXParser parser = factory.newSAXParser();
			XmlResultHandler handler = new XmlResultHandler();
			parser.parse(Networking.requestSendMessage(user, password, recipient, message), handler);
			return new String[]{String.valueOf(handler.getResult()),handler.getResultInfo()};
		}
		catch (Exception e)
		{
			Log.e("MessageSender", e.getMessage());
			throw new RuntimeException(e);
		}
	}
}
